package com.smartscreen.attendancemanage.controller;

import com.smartscreen.attendancemanage.dto.CreateAttendanceRuleRequest;
import com.smartscreen.attendancemanage.entity.AttendanceRule;
import com.smartscreen.attendancemanage.service.AttendanceRuleService;
import com.smartscreen.common.response.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/attendance")
public class AttendanceRuleController {
    
    @Autowired
    private AttendanceRuleService attendanceRuleService;
    
    @PostMapping("/rules")
    public ApiResponse<Map<String, String>> createAttendanceRule(
            @RequestBody CreateAttendanceRuleRequest request) {
        String ruleId = attendanceRuleService.createAttendanceRule(request);
        Map<String, String> data = new HashMap<>();
        data.put("ruleId", ruleId);
        return ApiResponse.created("签到规则创建成功", data);
    }
    
    @GetMapping("/rules")
    public ApiResponse<List<AttendanceRule>> getAllAttendanceRules() {
        List<AttendanceRule> rules = attendanceRuleService.getAllAttendanceRules();
        return ApiResponse.success(rules);
    }
    
    @PutMapping("/rules/{ruleId}")
    public ApiResponse<Void> updateAttendanceRule(
            @PathVariable String ruleId,
            @RequestBody CreateAttendanceRuleRequest request) {
        attendanceRuleService.updateAttendanceRule(ruleId, request);
        return new ApiResponse<>(200, "更新成功");
    }
}